xxxxxxxxxx // rect(-boundaryX /2, -boundaryY /2, boundaryX, boundaryY); // translate(-width / 2, -height / 2) noFill(); rect(width/2 - boundaryX, height/2 - boundaryY, boundaryX *2, boundaryY *2) let vol = mic.getLevel(); if(vol > .03){ for(let i = 0; i < total; i++){ particles.push(new Particle(mouseX, mouseY)); } } let mappedVol = constrain(map(pow(vol, .5), 0, 1, 0.2, 5), 0, 3); for(let p of particles){ p.show(); p.move(mappedVol); p.checkEdges(); } //code that draws particles then deletes them for(let i = particles.length - 1; i > -1; i--){ // console.log(particles[i].checkLifetime()); if(particles[i].checkLifetime()){ particles.splice(i, 1); } } }class Particle{ constructor(startX, startY){ //"this." makes it a unique variable for each reference of it created this.pos = createVector(startX, startY); this.vel = createVector(random(-5, 5), random(-5, 5)); this.lifetime = 60; } checkLifetime(){ this.lifetime--; console.log(this.lifetime) if(this.lifetime < 0){ return true; } return false; } move(_vol){ //amplitude.getLevel() this.pos.add(this.vel.copy().mult(_vol)); // this.pos.add(this.vel); // console.log(vol) // this.pos.add(this.vel + (this.vel.copy().mult(vol * 10))); } checkEdges(){ if(this.pos.x > width/2 + boundaryX || this.pos.x < width/2 - boundaryX){ this.vel.x *= -1; } if(this.pos.y > height/2 + boundaryY || this.pos.y < height/2 -boundaryY){ this.vel.y *= -1; } } 